package com.restfb.example;

import static java.lang.System.out;

import com.restfb.Connection;
import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;
import com.restfb.types.Post;
import com.restfb.types.User;


/**
 * CS 6310 
 * Facebook Connection Class
 *  * @author Yoga</a>
 * @param <T>
 */

public class FacebookConnection<T> { 
private final FacebookClient facebookClient;
private Object accessToken;
//private static WebRequestor webRequestor;
//private static JsonMapper jsonMapper;
private Object facebookGraphExceptionMapper;

  public static void main(String[] args) {
	  if (args.length == 0)
		  throw new IllegalArgumentException("You must provide an OAuth access token parameter. "   + "See README for more information.");
    
	  String[] args1  = {"2227470867|2._H2aEJMwejJ4zY5u7sdWsg__.3600.1299139200-1564863831|nKyZkZbJCmn2A0w04XF0TAMhr2U"}; //My access token
	  String conn1 = "me/friends";
	  String conn2 = "me/feed";
	  String conn3 = "me/feed";
	  Class connType1 = User.class;
	  Class connType2 = Post.class;
	  Class connType3 = Post.class;
	  new FacebookConnection(args1[0]).runConnection(conn1, connType1);
  	}

 public FacebookConnection(String accessToken) {
	 facebookClient = new DefaultFacebookClient(accessToken);
	 }    
    
public <T>Connection<T> runConnection(String connection, Class<T> connectionType){
	out.println("TEST00000");
	if (connection == "me/friends")
	{
		out.println("calling...FRIENDS...");
		Connection<T> myFriends = facebookClient.fetchConnection(connection, connectionType);
		out.println("Count of my friends:" + myFriends.getData().size());
		return myFriends;
	}
	if (connection == "me/feed")
	{
		out.println("calling...FEED...");
		Connection<T> myFeed = (Connection<T>) facebookClient.fetchConnection(connection, connectionType);
		out.println("First item in my feed: " + ((Post) myFeed.getData().get(0)).getMessage());
		return myFeed;
	}
	if (connection == "me/events")
	{
		out.println("calling...FEED...");
		Connection<T> myEvent = (Connection<T>) facebookClient.fetchConnection(connection, connectionType);
		out.println("My event: " + ((Post) myEvent.getData().get(0)).getMessage());
		return myEvent;
	}
	return null;

}
}
